#ifndef ELASLIDERRANGE_H
#define ELASLIDERRANGE_H

#include <QPainter>
#include <QPropertyAnimation>
#include <QStyleOptionSlider>
#include <QSlider>
#include <QMouseEvent>
#include "ElaTheme.h"

#include "stdafx.h"
class ELA_EXPORT ElaSliderRange : public QSlider {
    Q_OBJECT
    Q_PROPERTY(qreal leftCircleRadius READ leftCircleRadius WRITE setLeftCircleRadius)
    Q_PROPERTY(qreal rightCircleRadius READ rightCircleRadius WRITE setRightCircleRadius)
public:
    ElaSliderRange(Qt::Orientation orientation = Qt::Horizontal, QWidget* parent = nullptr);
    ~ElaSliderRange();

    qreal leftCircleRadius() const { return _leftCircleRadius; }
    void setLeftCircleRadius(qreal radius) { _leftCircleRadius = radius; }
    qreal rightCircleRadius() const { return _rightCircleRadius; }
    void setRightCircleRadius(qreal radius) { _rightCircleRadius = radius; }

    void setRange(int left, int right);
    void setValue(int left, int right);
    void setLeftValue(int val);
    void setRightValue(int val);
    int getLeftValue();
    int getRightValue();
signals:
    void valueChanged(int, int);

protected:
    void paintEvent(QPaintEvent* event) override;
    void mousePressEvent(QMouseEvent* event) override;
    void mouseMoveEvent(QMouseEvent* event) override;
    void mouseReleaseEvent(QMouseEvent* event) override;
    void leaveEvent(QEvent* event) override;
    void wheelEvent(QWheelEvent* event) override;

private:
    int _leftValue;
    int _rightValue;
    mutable qreal _leftCircleRadius;
    mutable qreal _rightCircleRadius;
    ElaThemeType::ThemeMode _themeMode;
    bool _movingLeft;
    bool _movingRight;
    bool _lastMovedLeft;
    bool _hoverLeft = false;
    bool _hoverRight = false;
    void _startRadiusAnimation(qreal startRadius, qreal endRadius, bool isLeft);
};
#endif // ELASLIDERRANGE_H
